package com.newsReader.article.model;

import java.util.List;

import com.eova.common.base.BaseModel;

public class Article extends BaseModel<Article>{
	
	private static final long serialVersionUID = 1L;
	
	public static final Article dao = new Article();
	
	/**
	 * 文章列表
	 * @param 
	 * @return
	 */
	public List<Article> ArticleList(int id) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT cag.id caid,cag.title cagTitle,cag.imgurl caImg,arc.articleType,arc.title title,"); 
		sql.append(" arc.imgUrl,timgurl,thimgurl,arc.puTime,arc.id,arc.sumcomen,arc.sumzan ");
		sql.append(" FROM c_category cag INNER JOIN n_article arc ON cag.id=arc.coumnId where cag.id=?");
		return this.find(sql.toString(),id);
	}
	
	/*
	 * 订阅列表
	 */
	public List<Article> OrderArticleList() {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT cag.id caid,cag.title cagTitle,cag.imgurl caImg,arc.articleType,arc.title title,arc.imgUrl,timgurl,thimgurl,arc.puTime,arc.id,arc.sumcomen,arc.sumzan"); 
		sql.append(" FROM c_category cag INNER JOIN n_article arc ON cag.id=arc.coumnId ");
		sql.append(" WHERE (SELECT count(1) FROM c_category cag1"); 
		sql.append(" INNER JOIN n_article arc1 ON cag1.id=arc1.coumnId"); 
		sql.append(" WHERE arc1.puTime>arc.puTime AND cag1.id=cag.id)<1");
		return this.find(sql.toString());
	}
	
	//订阅列表详情
	public List<Article> OrderArticleDetailList(int id) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT cag.id caid,cag.title cagTitle,cag.imgurl caImg,arc.articleType,arc.title title,arc.imgUrl,timgurl,thimgurl,arc.puTime,arc.id,arc.sumcomen,arc.sumzan"); 
		sql.append(" FROM c_category cag INNER JOIN n_article arc ON cag.id=arc.coumnId where cag.id=?");
		return this.find(sql.toString(),id);
	}
	
	/*
	 * 文章详情
	 */
	public Article ArticleDetail(int id) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id,title,lefTitle,content,imgUrl,articleType,sumZan,sumComen,puTime FROM n_article where id=?");
		return this.findFirst(sql.toString(),id);
	}
	
	
}